﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Agr.CQRS.Domain.Events;
using NHibernate.AdoNet.Util;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace Tests.Agr.CQRS.Domain.Events
{
    [TestClass]
    public class When_DomainEvent_Is_Serialized
    {
        private BinaryFormatter serializer;
        private DomainEventImpl domainEvent;

        [TestInitialize]
        public void TestInitialize()
        {
            serializer = new BinaryFormatter();
            var orgDomainEvent = new DomainEventImpl { AggregateRootId = Guid.NewGuid(), Version = 1, SomeProperty = "SomeProperty" };
            using (var ms = new MemoryStream())
            {
                serializer.Serialize(ms, orgDomainEvent);
                ms.Position = 0;
                domainEvent = (DomainEventImpl)serializer.Deserialize(ms);
            }
        }

        [TestMethod]
        public void Then_The_DomainEvent_Properties_Have_Not_Been_Serialized()
        {
            Assert.AreEqual(Guid.Empty, domainEvent.AggregateRootId);
            Assert.AreEqual(0, domainEvent.Version);
            
            //concrete class property has been serialized (just to be sure)
            Assert.AreEqual("SomeProperty", domainEvent.SomeProperty);
        }

        
    }

    [Serializable]
    public class DomainEventImpl : DomainEvent
    {
        public string SomeProperty { get; set; }
    }
}
